﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

//importamos
using EventSys.BussinesEntities;
using Microsoft.Practices.Unity;
using EventSys.BussinesLogic;

namespace EventSys.MVC4Web.Controllers
{
   
    public class ActividadController : Controller
    {

        [Dependency]
        public IEventoService eventoService { get; set; }

        [Dependency]
        public ITipoActividadService tipoActividadService { get; set; }

        [Dependency]
        public IEstadoService estadoService { get; set; }

        [Dependency]
        public IActividadService actividadService { get; set; }

        [Dependency]
        public IAmbienteService ambienteService { get; set; }


        //GET
        public ActionResult Index()
        {

            var lista = actividadService.GetAllFromActividad();
            return View(lista);
        }

        //public ActionResult viewActividads(int id)
        //{
        //    //var detalle = eventoService.GetEventoById(id);

        //    var detalle = actividadService.GetActividadByIdEvento(id);

        //    return PartialView("_viewActividads", detalle);
        //}

        public ActionResult viewActividads(int id, Int32? page)
        {
            var pageNumber = page ?? 1;
            var detalle = actividadService.GetActividadByIdEvento(id, pageNumber, 4);

            return PartialView("_viewActividads", detalle);
        }


        ////******************  CREAR  *******************//
        public ActionResult Create()
        {
            //var idEvento = eventoService.GetEventoById(id);

            var tipoActividad = tipoActividadService.GetFromAllTipoActividad();
            ViewData["IdTipoActividad"] = new SelectList(tipoActividad, "idTipoActividad", "Descripcion");

            var ambiente = ambienteService.GetFromAllAmbiente();
            ViewData["idAmbiente"] = new SelectList(ambiente, "idAmbiente", "Descripcion");

            //enviamos el ultimo id de evento creado
            var idEvento = (from e in eventoService.GetAllEventos()
                            select e.idEvents).Last();
            var evento = eventoService.GetAllEventos();

            ViewData["idEvento"] = new SelectList(evento, "idEvents", "idEvents",idEvento);

            return View();
        }

        [HttpPost]
        public ActionResult Create(Actividad actividad)
        {
            actividadService.AddActividad(actividad);

            return RedirectToAction("Index","Evento");
        }


    }
}
